namespace pos.entity
{
using System;
using System.Data;
using System.Configuration;
using System.Text;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Criterion;
/// <summary>
/// t_sequence 的摘要说明
/// </summary>
public class t_sequence:IEntityUtil
{
	//   列名称哈希表 
	private static Hashtable m_colLabels;    	 
	public static Hashtable colLabels//
	{
		get{return m_colLabels;}
	}
	//表字段名称哈希表
	private static ArrayList m_colNames;     
	public static ArrayList  colNames　
	{
		get{return m_colNames;}
	}
	private Sequence __sequence;
	public long seqID  
	{
		get{return __sequence.seqID;}
		set{ __sequence.seqID=value;}
	}
	public String remark  
	{
		get{return __sequence.remark;}
		set{ __sequence.remark=value;}
	}
	public long sequenceNo  
	{
		get{return __sequence.sequenceNo;}
		set{ __sequence.sequenceNo=value;}
	}
	private static  SequenceDao dao=(SequenceDao)SpringContext.Context.GetObject("SequenceDao");
	public static SequenceDao DAO
	{
		get{return dao;}
		
	}
	
	public t_sequence()
	{
		__sequence=new Sequence();
	  	seqID=consts.long_min;
	  	remark="";
	  	sequenceNo=consts.long_min;
	  // dao=(SequenceDao)SpringContext.Context.GetObject("SequenceDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("seqID", @"序号标识");
		colNames.Add("seqID");
		m_colLabels.Add("remark", @"说明");
		colNames.Add("remark");
		m_colLabels.Add("sequenceNo", @"当前编号");
		colNames.Add("sequenceNo");
	  }
	
	}
	public t_sequence(Sequence entity )
	{
		__sequence=entity;
		
	  // dao=(SequenceDao)SpringContext.Context.GetObject("SequenceDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("seqID", @"序号标识");
		colNames.Add("seqID");
		m_colLabels.Add("remark", @"说明");
		colNames.Add("remark");
		m_colLabels.Add("sequenceNo", @"当前编号");
		colNames.Add("sequenceNo");
	  }
	
	}
	public Object uniqueResult(DetachedCriteria dc)
    {
        return dao.uniqueResult(dc);
    }
	 public DetachedCriteria DC 
     {
        	get{return DetachedCriteria.For(typeof(Sequence));}
     }
	public const string ENTITYNAME="t_sequence";
	public const int SEQN0=1;
	
    public void checkAdd()
    {
		int len;
	//try{Convert.ToInt64(seqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	seqID<consts.long_min+1)
			throw (new Exception("请输入序号标识"));
 if(				(				  string.Format("{0}",seqID)				  )=="0")
	 throw (new Exception("序号标识是主健，框架要求值不能为0"));				

	
	len=remark.Trim().Length;
	if(len>50)
		 throw (new Exception("说明字符长度最长不能超过50,当前长度为"+len.ToString()));	
	

	//try{Convert.ToInt64(sequenceNo);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	sequenceNo<consts.long_min+1)
			throw (new Exception("请输入当前编号"));

//unique="yes" 唯一性验证
    }
    public void checkUpdate()
    {
		int len;
	//try{Convert.ToInt64(seqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	seqID<consts.long_min+1)
			throw (new Exception("请输入序号标识"));
 if(				(				  string.Format("{0}",seqID)				  )=="0")
	 throw (new Exception("序号标识是主健，框架要求值不能为0"));				

	
	len=remark.Trim().Length;
	if(len>50)
		 throw (new Exception("说明字符长度最长不能超过50,当前长度为"+len.ToString()));	
	

	//try{Convert.ToInt64(sequenceNo);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	sequenceNo<consts.long_min+1)
			throw (new Exception("请输入当前编号"));

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("seqID", seqID);
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==1)
			return;
		if(list.Count==0)
			throw (new Exception("该记录已经被删除"));	
		else
			throw (new Exception("改纪录出现重名!"));
    }
    public void add()
    {
        try
        {
            checkAdd();
         	dao.Add(__sequence);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void delByseqID()
    {
    
        try
        {
          dao.Delete(__sequence);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }

    public  void update()
    {
        try
        {
            checkUpdate();
            dao.Update(__sequence);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void ExecDataUpdate(int rowNo)
    {
		if(m_updateRow==null)
			return;
		int ii=0;
m_updateRow(rowNo,ii++,				(				  string.Format("{0}",seqID)				  ));	
m_updateRow(rowNo,ii++,remark);	
m_updateRow(rowNo,ii++,				(				  string.Format("{0}",sequenceNo)				  ));	

    }
    public void ExecHeadInsert()
    {
		if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,50,"序号标识");
			m_insertHead(ii++,50,"说明");
			m_insertHead(ii++,50,"当前编号");
		}		
    }
    public void ExecDataInsert()
	{
		if(m_insertRow==null)
			return;
		int ii=0;
     	m_insertRow(0,ii++,				(				  string.Format("{0}",seqID)				  ));
     	m_insertRow(0,ii++,remark);
     	m_insertRow(0,ii++,				(				  string.Format("{0}",sequenceNo)				  ));
    }
    public void ExecDataInsertByQuery(DetachedCriteria dc)
    {
      
         IList list=dao.List(dc); 
        
        if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,50,"序号标识");
			m_insertHead(ii++,50,"说明");
			m_insertHead(ii++,50,"当前编号");
		}		
		
      if(m_insertRow!=null)
      {
        int j=0;
        foreach(Sequence obj in list)			
        {
		  int ii=0;
	     
m_insertRow(j,ii++,				(				  string.Format("{0}",obj.seqID)
				  )
);
m_insertRow(j,ii++,obj.remark.ToString());
m_insertRow(j,ii++,				(				  string.Format("{0}",obj.sequenceNo)
				  )
);
		j++;
        }
        

	
       }
    }

    
    public IList List(DetachedCriteria dc)
    {
        try
        {
           
            return dao.List(dc);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
    
    public bool Init(DetachedCriteria dc)
    {
    
    		Sequence obj=dao.Get(dc);
    		if(obj==null)
    			return false;
    		else
    		{
    			__sequence=obj;
            	return true;
            }
        
    }
    public static t_sequence Get(DetachedCriteria dc)
    {
    	
    	Sequence obj=((SequenceDao)SpringContext.Context.GetObject("SequenceDao"))
	 	.Get(dc);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_sequence( obj );
        
    }
	 public static t_sequence GetBySeqID(long val)
	 {
	 	Sequence obj=((SequenceDao)SpringContext.Context.GetObject("SequenceDao"))
	 	.GetBySeqID(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_sequence( obj );
	 	
	 	
	 }
	 public  bool InitBySeqID(long val)
	 {
	 	

	 	Sequence obj=dao.GetBySeqID(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__sequence=obj;
	 		return true;
	 	}
	 	
	 	
	 }
    
       public bool showInForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["seqID"]!=null)
		{
			Controls["seqID"].Text=				(				  string.Format("{0}",seqID)				  );
		}
		if(Controls["remark"]!=null)
		{
			Controls["remark"].Text=remark;
		}
		if(Controls["sequenceNo"]!=null)
		{
			Controls["sequenceNo"].Text=				(				  string.Format("{0}",sequenceNo)				  );
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    public  t_sequence Init(Sequence item)
    {
        __sequence=item;
        return this;
    }

    
     public bool initByForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["seqID"]!=null)
		{
			
			if(Controls["seqID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["seqID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{seqID=(v==""?consts.long_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["seqID"].Focus();
					throw  (new Exception("序号标识格式不正确！！"));
				}
				
			}
			else
			{
				try{seqID=(Controls["seqID"].Text==""?consts.long_min:Convert.ToInt32(Controls["seqID"].Text));}
				catch
				{
					 Controls["seqID"].Focus();
					throw  (new Exception("序号标识格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["remark"]!=null)
		{
			
			if(Controls["remark"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["remark"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{remark=v;}
				catch
				{
					 Controls["remark"].Focus();
					throw  (new Exception("说明格式不正确！！"));
				}
				
			}
			else
			{
				try{remark=Controls["remark"].Text;}
				catch
				{
					 Controls["remark"].Focus();
					throw  (new Exception("说明格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["sequenceNo"]!=null)
		{
			
			if(Controls["sequenceNo"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["sequenceNo"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{sequenceNo=(v==""?consts.long_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["sequenceNo"].Focus();
					throw  (new Exception("当前编号格式不正确！！"));
				}
				
			}
			else
			{
				try{sequenceNo=(Controls["sequenceNo"].Text==""?consts.long_min:Convert.ToInt32(Controls["sequenceNo"].Text));}
				catch
				{
					 Controls["sequenceNo"].Focus();
					throw  (new Exception("当前编号格式不正确！！"));
				}
				
			}
				
				
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    

}

}
